package sdk.webview.fmc.com.fmcsdk.activity;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.base.BaseActivity;
import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.util.Constant;
import sdk.webview.fmc.com.fmcsdk.util.ImageUtils;
import sdk.webview.fmc.com.fmcsdk.util.TitleBar;
import sdk.webview.fmc.com.fmcsdk.util.Utility;

/**
 * 关于
 */
public class AboutActivity extends BaseActivity {


    TitleBar titlebar;
    TextView aboutVersion;
    ImageView ivAbout;
    private String version;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_about;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        titlebar = (TitleBar) findViewById(R.id.titlebar);
        aboutVersion = (TextView) findViewById(R.id.about_version);
        ivAbout = (ImageView) findViewById(R.id.iv_about);


        //如果本地下载有关于的图片就加载
        Bitmap localBitmap = BitmapFactory.decodeFile(ImageUtils.getImagePath2(sharedPrefs.getString(Constant.ABOUT_BG, ""),this));
        if (localBitmap!=null)
            ivAbout.setImageBitmap(localBitmap);
        titlebar.setTitle(getString(R.string.about));
        //设置版本号
        PackageInfo info = null;
        try {
            info = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            logger.info("AboutActivity", e.getMessage());
        }
        version = info.versionName;
        boolean isSdk = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(Constant.IS_SDK, false);
        String  time;
        if (!isSdk){
              time = (String) Utility.getMetaData(context, Constant.FMC_VERSION_TIME);
            if (!TextUtils.isEmpty(time)){
                String[] split = time.split("_");
                aboutVersion.setText(String.format(getString(R.string.version), version, split[1]));
            }
        }else {
            time = "20191021165201";
            aboutVersion.setText(String.format(getString(R.string.version), version, time));
        }




    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }


}